﻿// CWndModAnalysis.cpp: 实现文件
//

#include "pch.h"
#include "GameHacker.h"
#include "CWndModAnalysis.h"
#include "afxdialogex.h"


// CWndModAnalysis 对话框

IMPLEMENT_DYNAMIC(CWndModAnalysis, CDialogEx)

CWndModAnalysis::CWndModAnalysis(CWnd* pParent /*=nullptr*/)
	: CDialogEx(IDD_MOD_ANALYSIS, pParent)
{

}

CWndModAnalysis::~CWndModAnalysis()
{
}

void CWndModAnalysis::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_LIST1, m_lstModAnalysis);
}

void CWndModAnalysis::OnCancel()
{
}

void CWndModAnalysis::OnOK()
{
}


BEGIN_MESSAGE_MAP(CWndModAnalysis, CDialogEx)
	ON_NOTIFY(NM_CUSTOMDRAW, IDC_LIST1, &CWndModAnalysis::OnNMCustomdrawList1)
END_MESSAGE_MAP()


// CWndModAnalysis 消息处理程序


BOOL CWndModAnalysis::OnInitDialog()
{
	CDialogEx::OnInitDialog();

	// TODO:  在此添加额外的初始化
		//设置listControl的样式
	long lStyle;
	lStyle = GetWindowLongPtr(m_lstModAnalysis.m_hWnd, GWL_STYLE);
	lStyle |= LVS_REPORT;
	SetWindowLongPtr(m_lstModAnalysis.m_hWnd, GWL_STYLE, lStyle);
	lStyle = m_lstModAnalysis.GetExtendedStyle();
	lStyle |= LVS_EX_FULLROWSELECT;//一次选中一整行
	lStyle |= LVS_EX_GRIDLINES;//设置显示格子线
	m_lstModAnalysis.SetExtendedStyle(lStyle);

	m_lstModAnalysis.InsertColumn(0, L"模块名称", 0, 200);
	m_lstModAnalysis.InsertColumn(1, L"基址", 0, 100);
	m_lstModAnalysis.InsertColumn(2, L"大小", 0, 100);
	m_lstModAnalysis.InsertColumn(3, L"文件位置", 0, 400);
	m_lstModAnalysis.InsertColumn(4, L"状态", 0, 200);

	return TRUE;  // return TRUE unless you set the focus to a control
				  // 异常: OCX 属性页应返回 FALSE
}


void CWndModAnalysis::OnNMCustomdrawList1(NMHDR* pNMHDR, LRESULT* pResult)
{
	LPNMCUSTOMDRAW pNMCD = reinterpret_cast<LPNMCUSTOMDRAW>(pNMHDR);
	// TODO: 在此添加控件通知处理程序代码
	*pResult = 0;

	NMLVCUSTOMDRAW* lp = (NMLVCUSTOMDRAW*)pNMHDR;
	auto& nmcd = lp->nmcd;
	switch (nmcd.dwDrawStage) {
	case CDDS_PREPAINT:
		*pResult = CDRF_NOTIFYITEMDRAW;
		break;
	case CDDS_ITEMPREPAINT:
	{
		DWORD dwIndex = m_lstModAnalysis.GetItemData(nmcd.dwItemSpec);
		COLORREF colors[]{ RGB(0,0,255), RGB(255,0,0)};
		lp->clrText = colors[dwIndex];
		*pResult = CDRF_DODEFAULT;
	}
	break;
	}
}
